package com.jr.service.impl;

import com.jr.dao.IEmployeesDao;
import com.jr.dao.IUsersDao;
import com.jr.dao.impl.EmployeesDaoImpl;
import com.jr.dao.impl.UserDaoImpl;
import com.jr.pojo.Employees;
import com.jr.service.IEmployeesService;
import com.jr.util.PageHelper;

import java.util.ArrayList;

public class EmployeesServiceImpl implements IEmployeesService {

    IEmployeesDao ied = new EmployeesDaoImpl();
    IUsersDao iud = new UserDaoImpl();

    @Override
    public boolean addEmployees(Employees employees) {
        return ied.insertEmployees(employees)>0?true:false;
    }

    @Override
    public boolean changeEmployees(Employees employees) {
        return ied.updateEmployees(employees)>0?true:false;
    }

    @Override
    public Employees queryEmployeeByName(Integer employeeId) {
        return ied.selectEmployeesByEmployeeId(employeeId);
    }

    @Override
    public boolean removeEmployee(Integer employeeId) {
        int id = iud.selectIdByEmployeeId(employeeId);
        if(id == 0){
            return false;//id不存在
        }else{
            boolean bUser = iud.deleteUsersByEmployeeId(employeeId)>0?true:false;
            boolean bEmp = ied.deleteEmployeesByEmployeeId(employeeId)>0?true:false;
            if(bUser && bEmp){
                return true;
            }else {
                return false;
            }
        }
    }

    @Override // 分页查询 总条数
    public int queryPageDataCount() {
        return ied.selectPageDataCount();
    }

    @Override // 分页查询 查询当前页面 展示集合
    public ArrayList<Employees> queryIndexData(PageHelper ph) {
        return ied.selectIndexDate(ph);
    }

    @Override // 分页查询 -- 按名字 查 -- 总条数
    public int selectPageDataCountByName(String name) {
        return ied.selectPageDataCountByName(name);
    }

    @Override // 分页查询 按名字 查询 展示集合
    public ArrayList<Employees> selectIndexDateByName(String name, PageHelper ph) {
        return ied.selectIndexDateByName(name,ph);
    }
}
